﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style type="text/css">
    .topPanel .search .input-group .form-control {
        padding: 4px 5px !important;
        height: 22px !important;
        margin: 0 10px !important;
        width: 80%;
    }

    .topPanel .search table td {
       height: 30px;
       line-height: 30px;
   }
    .layoutDiv {
        float: left;
        height: 30px;
        line-height: 30px;
        margin: 10px 10px !important;
    }
</style>
<script type="text/javascript">
    $(function () {
        var queryJson = {
            F_Status: $("#state_horizon a.active").attr('data-value')
        }; 
        gridList(queryJson); 
        $("#state_horizon a.btn-default").click(function () {
            $("#state_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            searchData();
        });
    }); 
    
    function gridList(queryJson) {
        var $gridList = $("#gridList");                
        $gridList.dataGrid({
            url: "/TradingFlow/TradingManage/GetGridDataJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: $(window).height() - 120,
            colModel: [
                { label: '订单类型', name: 'F_Type', align: 'left' },
                { label: '订单名称', name: 'SiteName', align: 'left' },
                { label: '订单明细', name: 'SpaceName', align: 'left' },
                { label: '租赁开始时间', name: 'F_StartTime', align: 'left' },
                { label: '租赁结束时间', name: 'F_EndTime', align: 'left' },
                { label: '客户名称', name: 'F_UserName', align: 'left' },
                { label: '定金(元)', name: 'F_OrderPrice', align: 'right' },
                { label: '订单价(元)', name: 'F_Price', align: 'right' },
                { label: '订单总价(元)', name: 'F_TotalPrice', align: 'right' },                
                { label: '下单时间', name: 'F_CreatorTime', align: 'left' },
                { label: '客户留言', name: 'F_Remark', align: 'left' },
                { label: '', name: 'F_Status', hidden: true }, 
                { label: '', name: 'F_Id', hidden: true },                
            ],
            pager: "#gridPager",            
            viewrecords: true,
            ondblClickRow: function (rowid, iRow, iCol, e) {
                var rowobj = $gridList.getRowData(rowid);                
                if (rowobj["F_Status"] == "1") {
                    layer.confirm('确认订单是否有档期?', {
                        btn: ['有档期', '无档期']
                    },
                        function (index, layero) {
                            ChangeState(rowobj["F_Id"], 2);
                            layer.closeAll();
                        },
                        function (index, layero) {
                            ChangeState(rowobj["F_Id"], 6);
                            layer.closeAll();
                        }
                    );
                } else if (rowobj["F_Status"] == "6") {
                    layer.confirm('确认订单是否同意退款?', {
                        btn: ['确认退款', '暂不退款']
                    },
                        function (index, layero) {
                            ChangeState(rowobj["F_Id"], 7);
                            layer.closeAll();
                        },
                        function (index, layero) {                            
                            layer.closeAll();
                        }
                    );
                } 
            }
        });           
    }

    function ChangeState(id,state) {
        $.ajax({
            url: "/TradingFlow/TradingManage/ChangeOrderState",
            dataType: "json",
            data: { F_Id: id, F_Status: state },
            async: false,
            success: function (data) {
                searchData();
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
                console.log(textStatus);
                console.log(errorThrown);
            }
        });
    }

    function searchData() {        
        var queryJson = {
            F_Status: $("#state_horizon a.active").attr('data-value')
        };
        var $gridList = $("#gridList"); 
        $gridList.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }
</script>
<div class="topPanel">
    <div id="state_horizon" class="btn-group layoutDiv">
        <a class="btn btn-default active" data-value="0">下单未支付</a>     
        <a class="btn btn-default" data-value="1">已付定金,档期待确认</a>
        <a class="btn btn-default" data-value="2">待支付尾款</a>
        <a class="btn btn-default" data-value="3">已支付尾款</a>
        <a class="btn btn-default" data-value="6">退款申请</a>
        <a class="btn btn-default" data-value="7">退款完成</a>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>        
    </div>    
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>

